package com.yupi.mybi.bimq;


import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.yupi.mybi.constant.MqConstant;
import org.springframework.amqp.core.Exchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 用于创建测试程序用到的交换机和队列（只用在程序启动前执行一次）
 */
@Configuration
public class BiInitMain {

    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        channel.exchangeDeclare(MqConstant.BI_EXCHANGE, "direct");
        channel.queueDeclare(MqConstant.BI_QUEUE, true, false, false, null);
        channel.queueBind(MqConstant.BI_QUEUE, MqConstant.BI_EXCHANGE, MqConstant.BI_ROUTING_KEY);

    }
}
